﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Builder
{
    /// <summary>
    /// Provides implementation for ITagBuilder. Execute Concrete Builder role in Builder pattern
    /// </summary>
    public class TagBuilder: ITagBuilder
    {
        
        private readonly Tag tag;   // Tag class object

        /// <summary>
        /// Contructor
        /// </summary>
        /// <param name="tag"></param>
        public TagBuilder(Tag tag)
        {
            this.tag = tag;
        }

        /// <summary>
        /// Implement Render method in ITagBuilder interface
        /// </summary>
        /// <returns></returns>
        public string Render()
        {
            var attributes = String.Empty;

            foreach (KeyValuePair<string, string> attribute in tag.Attributes)
            {
                attributes += String.Format(" {0}='{1}'",  attribute.Key, attribute.Value);
            }

            var result = String.Format(Tag.TagPattern, tag.Name, attributes, tag.Content);

            return result;
        }
    }
}
